package ro.msg.quiz.repository;

/**
 * Author Vlad.
 */
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * This is Question class.
 */
@XmlRootElement(name = "question")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Question {
	private int id;
	private int type; // 1 - single choice, 2 - multiple choice, 3 - text
	private String text;
	private String lastEdited;
	private static String dateFormatString = "dd.MM.yyyy";

	/**
	 * Constructor
	 */
	public Question() {
		this.setId(-1);
		this.setType(0);
		this.setText(null);

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * Constructor
	 * 
	 * @param id
	 *            The id of question.
	 * @param type
	 *            The type of question.
	 * @param text
	 *            The text of question.
	 */
	public Question(int id, int type, String text) {
		this.setId(id);
		this.setType(type);
		this.setText(text);

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * 
	 * @return Returns the text of question.
	 */
	// @XmlElement
	public String getText() {
		return text;
	}

	/**
	 * Sets the text of question.
	 * 
	 * @param text
	 *            The text of question to be set.
	 */
	public void setText(String text) {
		this.text = text;

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * 
	 * @return Returns the id of question.
	 */
	// @XmlElement
	public int getId() {
		return id;
	}

	/**
	 * Sets the id of question.
	 * 
	 * @param id
	 *            The id of question to be set.
	 */
	public void setId(int id) {
		this.id = id;

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * Sets the last edited of question.
	 * 
	 * @param lastEdited
	 *            The last edited of question to be set.
	 */
	public void setLastEdited(String lastEdited) {
		this.lastEdited = lastEdited;

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * 
	 * @return Returns the last edited of question.
	 */
	// @XmlElement
	public String getLastEdited() {
		return this.lastEdited;
	}

	/**
	 * Sets the type of question.
	 * 
	 * @param type
	 *            The type to be set.
	 */
	public void setType(int type) {
		this.type = type;

		DateFormat dateFormat = new SimpleDateFormat(dateFormatString);
		Date date = new Date();
		this.lastEdited = dateFormat.format(date);
	}

	/**
	 * Returns an arraylist with the options of the Question
	 * 
	 * @return null because this method will always be derived
	 */
	public ArrayList<String> getOptions() {
		return null;

	}

	/**
	 * Returns an arraylist with the answers of the Question
	 * 
	 * @return null because this method will always be derived
	 */
	public ArrayList<String> getAnswers() {
		return null;
	}

	/**
	 * @return Returns the type of question.
	 */
	// @XmlElement
	public int getType() {
		return type;
	}

	/**
	 * This method prints the id and text of question.
	 */
	@Override
	public String toString() {
		return id + " " + text;
	}
}
